<template>
  <div class="app-container">
    <el-card>
      <el-form :model="queryList" :inline="true" label-width="68px">
        <el-form-item label="集团名称">
          <el-input v-model="queryList.name" placeholder="请输入集团名称" clearable style="width: 150px" />
        </el-form-item>
        <el-form-item label="集团编号">
          <el-input v-model="queryList.code" placeholder="请输入集团编号" clearable style="width: 150px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-plus" @click="addDialog('add')">新增</el-button>
          <el-button type="primary" icon="el-icon-search" @click="filterDire">查询</el-button>
          <el-button type="danger" icon="el-icon-refresh" @click="clearAll">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card>
      <el-table :data="groupList" border height="605px">
        <el-table-column type="index" label="序号" align="center"> </el-table-column>
        <el-table-column prop="code" label="部门代码" align="center"></el-table-column>
        <el-table-column prop="name" label="部门名称" align="center"></el-table-column>
        <el-table-column prop="pK_ORG" label="企业编号" align="center"></el-table-column>
        <el-table-column prop="dept_id" label="部门" width="180" align="center"></el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="addDialog('edit',scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="total, prev, pager, next, sizes,jumper" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :current-page="queryList.pageNum" :page-size="queryList.pageSize"
        :page-sizes="[10, 20, 50,100]" :total="total">
      </el-pagination>
    </el-card>
    <groupAdd ref="groupAddRef" :visible.sync="visible" @addSuccess="addSuccess"/>
  </div>
</template>

<script>
  import groupAdd from "@/components/BasicInformation/groupAdd.vue"
  import {
    findNccBasicManufacurerInfoData,
  } from '@/api/basic/PersonnelInformation.js'
  export default {
    components: {
      groupAdd
    },
    data() {
      return {
        queryList: {
          name: '', //集团名称
          code: '', //集团编号
        },
        groupList: [], //el-table数据
        total: 0,
        visible: false,
      };
    },
    created() {
      this.getNccGroupList();
    },
    methods: {
      getNccGroupList() {
        findNccBasicManufacurerInfoData(this.queryList).then(response => {
          this.groupList = response.rows;
          this.total = response.total;
        });
      },
      //新增/修改后刷新列表
      addSuccess(){
        this.getNccGroupList();
      },
      clearAll() {
        this.queryList = {
          name: "",
          code: null,
        };
        this.getNccGroupList();
      },
      filterDire() {
        this.getNccGroupList()
      },

      addDialog(type, row) {
        this.visible = true;
        this.$refs.groupAddRef.openDialog(type, row);
      },
      handleSizeChange(newsize) {
        this.queryList.pageNum = 1
        this.queryList.pageSize = newsize
        this.getNccGroupList()
      },
      handleCurrentChange(newpage) {
        this.queryList.pageNum = newpage
        this.getNccGroupList()
      },
    }
  };
</script>

<style scoped>
  .app-container {
    padding: 20px;
  }

  .el-card {
    margin-bottom: 20px;
  }

  .btn el-button {
    margin-bottom: 20px;
  }

  .el-pagination {
    float: right;
    margin: 20px;
  }
</style>
